package com.example.hanchen.yongkanggy.home.fragment;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ProgressBar;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.hanchen.yongkanggy.R;
import com.example.hanchen.yongkanggy.home.activity.EarlyWarningDetailsActivity;
import com.example.hanchen.yongkanggy.home.activity.InspectionDetailsActivity;
import com.example.hanchen.yongkanggy.home.activity.LatestNewsActivity;
import com.example.hanchen.yongkanggy.home.adapter.HomeAdapter;
import com.example.hanchen.yongkanggy.home.adapter.WarnlitemAdapter;
import com.example.hanchen.yongkanggy.home.base.BaseFragment;
import com.example.hanchen.yongkanggy.utils.RoundedSeekBar;

import java.util.ArrayList;
import java.util.List;

public class HomeFragment extends BaseFragment {

    TextView textViewProgress, itinerant,tvPermanentStaff,tv_View_All;
    ProgressBar progressBar,itinerantPr,PermanentStaffPr;//
    RecyclerView rv_list;
    HomeAdapter homeAdapter;
    List<String> stringList = new ArrayList<>();

    public static HomeFragment newInstance() {//int typePosition
        Bundle args = new Bundle();
        HomeFragment fragment = new HomeFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @SuppressLint("MissingInflatedId")
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_home, container, false);
        textViewProgress = view.findViewById(R.id.textViewProgress);
        itinerant = view.findViewById(R.id.itinerant);
        tvPermanentStaff = view.findViewById(R.id.tvPermanentStaff);
        progressBar = view.findViewById(R.id.progressBar);
        itinerantPr = view.findViewById(R.id.itinerantPr);
        PermanentStaffPr = view.findViewById(R.id.PermanentStaffPr);
        rv_list = view.findViewById(R.id.rv_list);
        tv_View_All = view.findViewById(R.id.tv_View_All);

        for (int i = 0; i < 8; i++) {
            stringList.add("");
        }

        homeAdapter = new HomeAdapter(getActivity(), new HomeAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(int position) {
                startActivity(new android.content.Intent(getActivity(), InspectionDetailsActivity.class));
            }
        });
        rv_list.setLayoutManager(new LinearLayoutManager(getActivity()));
        rv_list.setAdapter(homeAdapter);
        homeAdapter.setTabData(stringList);


        tv_View_All.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(getActivity(), LatestNewsActivity.class));
            }
        });

        initData();
        return view;
    }

    private void initData() {
        updateProgress(75); // 更新进度到 75%
    }

    private void updateProgress(int progress) {
        progressBar.setProgress(progress);
        textViewProgress.setText(progress + "%");

        itinerantPr.setProgress(20);
        itinerant.setText(20 + "%");

        PermanentStaffPr.setProgress(40);
        tvPermanentStaff.setText(40 + "%");
    }
}
